﻿#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include "JobConfImpl.h"
#include <map>
#include <string>
#include <hadoop/Error.h>
#include <hadoop/StringUtils.hh> //for toInt ... 

namespace HadoopPipes {

    void JobConfImpl::set(const std::string& key, const std::string& value) {
      values[key] = value;
    }

    bool JobConfImpl::hasKey(const std::string& key) const {
      return values.find(key) != values.end();
    }

    const std::string& JobConfImpl::get(const std::string& key) const {
     auto itr = values.find(key);
      if (itr == values.end()) {
        throw HadoopUtils::Error("Key " + key + " not found in JobConf");
      }
      return itr->second;
    }

    int JobConfImpl::getInt(const std::string& key) const {
      const std::string& val = get(key);
      return HadoopUtils::toInt(val);
    }

    float JobConfImpl::getFloat(const std::string& key) const {
      const std::string& val = get(key);
      return HadoopUtils::toFloat(val);
    }

    bool JobConfImpl::getBoolean(const std::string& key) const {
      const std::string& val = get(key);
      return HadoopUtils::toBool(val);
    }

}